import { Component, OnInit } from '@angular/core';
import {Router, ActivatedRoute} from '@angular/router';
import {ServiceLogicService} from '../../service/service-logic.service';
import {PunchRecord} from '../../domain/admin';
import {Location} from '@angular/common';

@Component({
  selector: 'app-punch-in',
  templateUrl: './punch-in.component.html',
  styleUrls: ['./punch-in.component.css']
})
export class PunchInComponent implements OnInit {
  private data: any;
  date = new Date();
  addARecord() {
    this.logicService.getWorkNo(this.data.admin_id)
      .then(response => {
        console.log(response[0].dept_no);
        const punchRecord = {
          admin_id: this.data.admin_id,
          dept_no: response[0].dept_no,
          // dept_no: this.data.dept_no,
          year: this.date.getFullYear().toString(),
          month: (this.date.getMonth() + 1).toString(),
          day: this.date.getDate().toString(),
          time: this.date.getHours().toString() + ':' + this.date.getMinutes().toString()
        };
        console.log(punchRecord);
        this.logicService.addPunchInRecord(punchRecord)
          .then(response2 => {
            if (punchRecord) { alert('签到成功！'); }
          });
      });
  }
  back() {
    this.location.back();
  }
  constructor(private activateRoute: ActivatedRoute, private logicService: ServiceLogicService, private location: Location) { }
  ngOnInit() {
    console.log(new Date());
    console.log(1);
    this.activateRoute.queryParams.subscribe(params => {
      this.data = params;
    });
    console.log(2);
  }

}
